package edu.com.wjt219971332.dao;

import edu.com.wjt219971332.entity.Audiencevote;
import org.apache.ibatis.annotations.*;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface AudiencevoteDao {

    @Select("SELECT * FROM audiencevote WHERE uservoteid = #{uservoteid}")
    Audiencevote queryById(Integer uservoteid);

    @Select("SELECT * FROM audiencevote LIMIT #{pageable.offset}, #{pageable.pageSize}")
    List<Audiencevote> queryAllByLimit(Audiencevote audiencevote, @Param("pageable") Pageable pageable);

    @Select(" select count(1) from audiencevote")
    long count(Audiencevote audiencevote);

    @Insert("INSERT INTO audiencevote (userid, competitionid, singerid) VALUES (#{userid} ,#{competitionid}, #{singerid})")
    @Options(useGeneratedKeys = true, keyProperty = "uservoteid")
    int insert(Audiencevote audiencevote);

    int insertBatch(@Param("entities") List<Audiencevote> entities);


    int insertOrUpdateBatch(@Param("entities") List<Audiencevote> entities);

    @Update("UPDATE audiencevote SET userid = #{userid}, competitionid = #{competitionid},singerid = #{singerid} WHERE uservoteid = #{uservoteid}")
    int update(Audiencevote audiencevote);

    @Delete("DELETE FROM audiencevote WHERE uservoteid = #{uservoteid}")
    int deleteById(Integer uservoteid);
    @Select("SELECT * FROM audiencevote where userid = #{userid} and competitionid = #{competitionid}")
    Audiencevote weiyi(@Param("userid") int userid, @Param("competitionid") int competitionid);
    @Select("SELECT count(*) FROM audiencevote where singerid = #{singerid} and competitionid = #{competitionid}")
    int countvote(@Param("competitionid")Integer competitionid, @Param("singerid")Integer singerid);
    @Delete("DELETE FROM audiencevote WHERE userid = #{userid} and competitionid = #{competitionid}")
    int deleteByuserid(@Param("userid")Integer userid, @Param("competitionid")Integer competitionid);
}

